﻿namespace Agent
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Security;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Security.Cryptography;
    using System.Security.Cryptography.X509Certificates;
    using System.Text;
    using System.Windows;
    using System.Xml;
    using System.Xml.Linq;
    using TheSafety;

    internal class WebRequestManager
    {
        [CompilerGenerated]
        private static Func<XElement, long> a;

        private static long a(DateTime A_0)
        {
            TimeSpan span = (TimeSpan) (A_0 - new DateTime(0x7b2, 1, 1, 0, 0, 0));
            return (long) span.TotalSeconds;
        }

        private static DateTime a(string A_0)
        {
            double result = 0.0;
            double.TryParse(A_0, out result);
            DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
            return time.AddSeconds(result);
        }

        [CompilerGenerated]
        private static long a(XElement A_0)
        {
            return DateTime.Parse(A_0.Attribute("date").Value).ToFileTime();
        }

        public static List<ManagementChangeInfoItem> a(string A_0, out string A_1)
        {
            A_1 = "";
            List<ManagementChangeInfoItem> list = new List<ManagementChangeInfoItem>();
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=change_subscription&order_id={0}", A_0) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        if (document.Element("root").Element("error") != null)
                        {
                            A_1 = d(document.Element("root").Element("error").Value);
                            if (A_1 == "nosub")
                            {
                                A_1 = e.c("There is no that Subscription. Update your data.");
                            }
                            else
                            {
                                A_1 = e.c("Not enough money for continue. Add funds to your account.");
                            }
                        }
                        else
                        {
                            foreach (XElement element in document.Element("root").Descendants("sub"))
                            {
                                ManagementChangeInfoItem item = new ManagementChangeInfoItem();
                                item.e(d(element.Attribute("id").Value));
                                item.b(d(element.Attribute("type").Value));
                                item.d(d(element.Attribute("exp").Value));
                                item.c(d(element.Attribute("rem").Value));
                                item.a(d(element.Value));
                                item.a(false);
                                list.Add(item);
                            }
                            foreach (XElement element2 in document.Element("root").Descendants("return"))
                            {
                                ManagementChangeInfoItem item2 = new ManagementChangeInfoItem();
                                item2.e(d(element2.Attribute("id").Value));
                                item2.b(d(element2.Attribute("type").Value));
                                item2.d(d(element2.Attribute("exp").Value));
                                item2.c(d(element2.Attribute("rem").Value));
                                item2.a(d(element2.Value));
                                item2.a(true);
                                list.Add(item2);
                            }
                            return list;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ChangeSubscriptionInfo", exception);
                    return null;
                }
            }
            return null;
        }

        public static bool a(string A_0, string A_1)
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=change_password_vpn&usernamevpn={0}&password_new={1}", A_0, A_1) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        if (document.Element("root").Element("error") == null)
                        {
                            goto Label_0184;
                        }
                        string str = d(document.Element("root").Element("error").Value);
                        if (str == null)
                        {
                            goto Label_0168;
                        }
                        if (!(str == "nopass"))
                        {
                            if (str == "wrong_usernamevpn")
                            {
                                goto Label_010E;
                            }
                            if (str == "wrong_passwordvpn")
                            {
                                goto Label_012D;
                            }
                            if (str == "nosub")
                            {
                                goto Label_014C;
                            }
                            goto Label_0168;
                        }
                        MessageBox.Show(e.c("InvalidLoginAndPassword") + "\n");
                    }
                    goto Label_01EC;
                Label_010E:
                    MessageBox.Show(e.c("For Username VPN uses only symbols a-z and 0-9, it should be 6-15 symbols in length.") + "\n");
                    goto Label_01EC;
                Label_012D:
                    MessageBox.Show(e.c("For Password VPN uses only symbols a-z and 0-9, it should be 6-15 symbols in length.") + "\n");
                    goto Label_01EC;
                Label_014C:
                    MessageBox.Show(e.c("There is no that Subscription. Update your data.") + "\n");
                    goto Label_01EC;
                Label_0168:
                    MessageBox.Show(e.c("Program Error. Contact Support for this error.") + "\n");
                    goto Label_01EC;
                Label_0184:
                    if ((document.Element("root").Element("result") != null) && (d(document.Element("root").Element("result").Value).Length == 4))
                    {
                        return true;
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ChangePasswordVPN", exception);
                    return false;
                }
            }
        Label_01EC:
            return false;
        }

        public static AgentUser a(string A_0, string A_1, out bool A_2)
        {
            A_2 = false;
            string str = "deistvo=download&glog80=" + A_0 + "&rpass3t=" + b(A_1);
            try
            {
                XDocument document = c("https://thesafety.us/billing/gui/guio", str + "&ver=1.2");
                if (((document == null) || (d(document.Element("root").Element("auth").Value).Length != 4)) || (d(document.Element("root").Element("license").Value).Length != 4))
                {
                    goto Label_014C;
                }
                AgentUser user = new AgentUser();
                user.a(A_0);
                user.b(A_1);
                string str2 = d(document.Element("root").Element("license").Attribute("type").Value);
                if (str2 != null)
                {
                    if (!(str2 == "0"))
                    {
                        if (str2 != "1")
                        {
                            if (str2 != "2")
                            {
                                return user;
                            }
                            goto Label_012D;
                        }
                    }
                    else
                    {
                        user.a(LicenseType.Limited);
                        return user;
                    }
                    user.a(LicenseType.Premium);
                }
                return user;
            Label_012D:
                user.a(LicenseType.Elite);
                return user;
            }
            catch (Exception exception)
            {
                ConfigManager.a("DoLoginRequest", exception);
                A_2 = true;
            }
        Label_014C:
            return null;
        }

        protected static bool a(object A_0, X509Certificate A_1, X509Chain A_2, SslPolicyErrors A_3)
        {
            return true;
        }

        public static string a(string A_0, string A_1, string A_2, string A_3)
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=send_message&usernamevpn={0}&filename={1}&log={2}&message={3}", new object[] { A_0, A_1, A_2, A_3 }) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        if (document.Element("root").Element("error") != null)
                        {
                            return d(document.Element("root").Element("error").Value);
                        }
                        if (document.Element("root").Element("result") != null)
                        {
                            if (d(document.Element("root").Element("result").Value).Length > 0)
                            {
                                return d(document.Element("root").Element("result").Value);
                            }
                            return null;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("SendToSupport", exception);
                    return null;
                }
            }
            return null;
        }

        public static bool a(string A_0, string A_1, string A_2, out string A_3)
        {
            A_3 = "";
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=change_subscription_finish&order_id={0}&rate={1}&type={2}", A_0, A_1, A_2) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        if (document.Element("root").Element("error") != null)
                        {
                            A_3 = d(document.Element("root").Element("error").Value);
                            if (A_3 == "nosub")
                            {
                                A_3 = e.c("There is no that Subscription. Update your data.");
                            }
                        }
                        else
                        {
                            return true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ChangeSubscriptionFinish", exception);
                    return false;
                }
            }
            return false;
        }

        public static string[] a(string A_0, string A_1, string A_2, string A_3, string A_4, string A_5, string A_6, string A_7)
        {
            if (AgentUser.a() != null)
            {
                string[] strArray2;
                try
                {
                    string text1 = string.Format("deistvo=wizard_buy_finish&subscribe={0}&dedip={1}&rate={2}&period={3}&gui_license={4}&promo={5}&usernamevpn={6}&passwordvpn={7}", new object[] { A_0, A_1, A_2, A_3, A_4, A_5, A_6, A_7 }) + a();
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=wizard_buy_finish&subscribe={0}&dedip={1}&rate={2}&period={3}&gui_license={4}&promo={5}&usernamevpn={6}&passwordvpn={7}", new object[] { A_0, A_1, A_2, A_3, A_4, A_5, A_6, A_7 }) + a());
                    if (document == null)
                    {
                        goto Label_036E;
                    }
                    string[] strArray = new string[2];
                    if (d(document.Element("root").Element("auth").Value).Length == 4)
                    {
                        if (document.Element("root").Element("error") != null)
                        {
                            string[] strArray10;
                            string key = d(document.Element("root").Element("error").Value);
                            if (key != null)
                            {
                                int num;
                                if (p.b == null)
                                {
                                    Dictionary<string, int> dictionary1 = new Dictionary<string, int>(7);
                                    dictionary1.Add("guilicense_exists", 0);
                                    dictionary1.Add("mistake", 1);
                                    dictionary1.Add("nofreeip", 2);
                                    dictionary1.Add("momoney", 3);
                                    dictionary1.Add("wrong_usernamevpn", 4);
                                    dictionary1.Add("wrong_passwordvpn", 5);
                                    dictionary1.Add("usernamevpn_exists", 6);
                                    p.b = dictionary1;
                                }
                                if (p.b.TryGetValue(key, out num))
                                {
                                    switch (num)
                                    {
                                        case 0:
                                            string[] strArray3;
                                            (strArray3 = strArray)[1] = strArray3[1] + e.c("That GUI License is already exist in your account.") + "\n";
                                            goto Label_0358;

                                        case 1:
                                            string[] strArray4;
                                            (strArray4 = strArray)[1] = strArray4[1] + e.c("Program Error. Contact Support for this error.") + "\n";
                                            goto Label_0358;

                                        case 2:
                                            string[] strArray5;
                                            (strArray5 = strArray)[1] = strArray5[1] + e.c("No free dedicated IP for this Subscription.") + "\n";
                                            goto Label_0358;

                                        case 3:
                                            string[] strArray6;
                                            (strArray6 = strArray)[1] = strArray6[1] + e.c("Not enough money for continue. Add funds to your account.") + "\n";
                                            goto Label_0358;

                                        case 4:
                                            string[] strArray7;
                                            (strArray7 = strArray)[1] = strArray7[1] + e.c("For Username VPN uses only symbols a-z and 0-9, it should be 6-15 symbols in length.") + "\n";
                                            goto Label_0358;

                                        case 5:
                                            string[] strArray8;
                                            (strArray8 = strArray)[1] = strArray8[1] + e.c("For Password VPN uses only symbols a-z and 0-9, it should be 6-15 symbols in length.") + "\n";
                                            goto Label_0358;

                                        case 6:
                                            string[] strArray9;
                                            (strArray9 = strArray)[1] = strArray9[1] + e.c("This Username VPN already exists. Choose other Username VPN.") + "\n";
                                            goto Label_0358;
                                    }
                                }
                            }
                            (strArray10 = strArray)[1] = strArray10[1] + e.c("Program Error. Contact Support for this error.") + "\n";
                        }
                        else if ((document.Element("root").Element("result") != null) && (d(document.Element("root").Element("result").Value).Length == 4))
                        {
                            strArray[0] = e.c("SuccessfullyBuying");
                        }
                    }
                Label_0358:
                    strArray2 = strArray;
                }
                catch (Exception exception)
                {
                    ConfigManager.a("BuySubscription", exception);
                    strArray2 = null;
                }
                return strArray2;
            }
        Label_036E:
            return null;
        }

        public static List<UniObj<string, string, string, string, string, string, string>> b()
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", "deistvo=subscriptions" + a());
                    if (((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4)) && (document.Element("root").Element("nosub") == null))
                    {
                        List<UniObj<string, string, string, string, string, string, string>> list = new List<UniObj<string, string, string, string, string, string, string>>();
                        foreach (XElement element in document.Element("root").Descendants("sub"))
                        {
                            list.Add(new UniObj<string, string, string, string, string, string, string>(d(element.Attribute("id").Value), d(element.Attribute("usernamevpn").Value), d(element.Attribute("exp_date").Value), d(element.Attribute("active").Value), (element.Attribute("dedip") != null) ? d(element.Attribute("dedip").Value) : "0", d(element.Value), (element.Attribute("icon") != null) ? d(element.Attribute("icon").Value) : ""));
                        }
                        foreach (XElement element2 in document.Element("root").Descendants("icon"))
                        {
                            if ((element2.Value != "") && !System.IO.File.Exists(ConfigManager.q() + "/config/" + d(element2.Attribute("name").Value) + ".png"))
                            {
                                System.IO.File.WriteAllBytes(ConfigManager.q() + "/config/" + d(element2.Attribute("name").Value) + ".png", Convert.FromBase64String(element2.Value));
                            }
                        }
                        return list;
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("GetSubscriptions", exception);
                    return null;
                }
            }
            return null;
        }

        protected static string b(string A_0)
        {
            string str = string.Empty;
            foreach (byte num in new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(A_0)))
            {
                str = str + num.ToString("X2");
            }
            return str;
        }

        public static ManagementInfoItem b(string A_0, out string A_1)
        {
            A_1 = "";
            ManagementInfoItem item = new ManagementInfoItem();
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=wizard_prolong_period&order_id={0}", A_0) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        if (document.Element("root").Element("error") != null)
                        {
                            A_1 = d(document.Element("root").Element("error").Value);
                            if (A_1 == "nosub")
                            {
                                A_1 = e.c("There is no that Subscription. Update your data.");
                            }
                            else
                            {
                                A_1 = e.c("Not enough money for continue. Add funds to your account.");
                            }
                        }
                        else
                        {
                            item.a(d(document.Element("root").Element("balance").Value));
                            foreach (XElement element in document.Element("root").Descendants("period"))
                            {
                                ManagementPeriodItem item2 = new ManagementPeriodItem();
                                item2.d(d(element.Attribute("id").Value));
                                item2.b(d(element.Attribute("cost").Value));
                                item2.c(d(element.Attribute("discount").Value));
                                item2.a(d(element.Value));
                                item.b().Add(item2);
                            }
                            foreach (XElement element2 in document.Element("root").Descendants("pkod"))
                            {
                                ManagementPromoCode code = new ManagementPromoCode();
                                code.b(d(element2.Attribute("discount").Value));
                                code.a(d(element2.Value));
                                item.c().Add(code);
                            }
                        }
                        return item;
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ProlongSubscriptionInfo", exception);
                    return null;
                }
            }
            return null;
        }

        public static bool b(string A_0, string A_1)
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=settings_main_password&password_old={0}&password_new={1}", b(A_0), b(A_1)) + a());
                    if (((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4)) && ((document.Element("root").Element("result") != null) && (d(document.Element("root").Element("result").Value).Length == 4)))
                    {
                        return true;
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ChangePassword", exception);
                    return false;
                }
            }
            return false;
        }

        public static bool b(string A_0, string A_1, string A_2, out string A_3)
        {
            A_3 = "";
            new ManagementInfoItem();
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=wizard_prolong_finish&order_id={0}&promo_code={1}&period={2}", A_0, A_1, A_2) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        if (document.Element("root").Element("error") != null)
                        {
                            A_3 = d(document.Element("root").Element("error").Value);
                            if (A_3 == "nosub")
                            {
                                A_3 = e.c("There is no that Subscription. Update your data.");
                            }
                            if (A_3 == "nomoney")
                            {
                                A_3 = e.c("Not enough money for continue. Add funds to your account.");
                            }
                        }
                        else if (d(document.Element("root").Element("result").Value).Length == 4)
                        {
                            return true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ProlongSubscription", exception);
                    return false;
                }
            }
            return false;
        }

        public static string c()
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", "deistvo=settings_balance" + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        return d(document.Element("root").Element("balance").Value);
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("GetBalance", exception);
                    return null;
                }
            }
            return null;
        }

        protected static MemoryStream c(string A_0)
        {
            return new MemoryStream(Convert.FromBase64String(A_0));
        }

        public static bool c(string A_0, out string A_1)
        {
            A_1 = "";
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=wizard_cancel_finish&order_id={0}", A_0) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        if (document.Element("root").Element("error") != null)
                        {
                            A_1 = d(document.Element("root").Element("error").Value);
                            if (A_1 == "nosub")
                            {
                                A_1 = e.c("There is no that Subscription. Update your data.");
                            }
                            else
                            {
                                A_1 = e.c("You can not return this Subscription.");
                            }
                        }
                        else if (d(document.Element("root").Element("result").Value).Length == 4)
                        {
                            return true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("CancelSubscription", exception);
                    return false;
                }
            }
            return false;
        }

        protected static XDocument c(string A_0, string A_1)
        {
            XDocument document = new XDocument();
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(WebRequestManager.a);
            try
            {
                if (ConfigManager.a())
                {
                    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(A_0);
                    request.Method = "POST";
                    request.UseDefaultCredentials = true;
                    request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
                    request.Timeout = 0x2ee0;
                    byte[] bytes = null;
                    bytes = Encoding.GetEncoding("utf-8").GetBytes(A_1);
                    request.ContentLength = bytes.Length;
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(bytes, 0, bytes.Length);
                    requestStream.Close();
                    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        string str2;
                        document = XDocument.Parse(reader.ReadToEnd().Trim(new char[] { ' ', '\n', '\r' }));
                        reader.Close();
                        if (document.Element("root").Element("ver").Value == "false")
                        {
                            MessageBox.Show(e.c("WrongVersion"), "", MessageBoxButton.OK, MessageBoxImage.Hand);
                        }
                        if (((AgentUser.a() != null) && (d(document.Element("root").Element("auth").Value).Length == 4)) && ((d(document.Element("root").Element("license").Value).Length == 4) && ((str2 = d(document.Element("root").Element("license").Attribute("type").Value)) != null)))
                        {
                            if (!(str2 == "0"))
                            {
                                if (str2 == "1")
                                {
                                    goto Label_021A;
                                }
                                if (str2 != "2")
                                {
                                    return document;
                                }
                                goto Label_0234;
                            }
                            if (AgentUser.a().b() != LicenseType.Limited)
                            {
                                AgentUser.a().a(LicenseType.Limited);
                            }
                        }
                        return document;
                    Label_021A:
                        if (AgentUser.a().b() != LicenseType.Premium)
                        {
                            AgentUser.a().a(LicenseType.Premium);
                        }
                        return document;
                    Label_0234:
                        if (AgentUser.a().b() != LicenseType.Elite)
                        {
                            AgentUser.a().a(LicenseType.Elite);
                        }
                    }
                    return document;
                }
            }
            catch (Exception exception)
            {
                ConfigManager.a("DoRequest", exception);
                MessageBox.Show(e.c("NoInternet"));
                throw new Exception(e.c("NoInternet"));
            }
            return null;
        }

        public static ManagementPromoItem d()
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", "deistvo=wizard_buy_subscription" + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        bool flag = false;
                        if (d(document.Element("root").Element("license").Attribute("type").Value) == "2")
                        {
                            flag = true;
                        }
                        ManagementPromoItem item = new ManagementPromoItem();
                        item.a(d(document.Element("root").Element("balance").Value));
                        if (document.Element("root").Element("money_return") != null)
                        {
                            item.b(d(document.Element("root").Element("money_return").Value));
                        }
                        item.a(new Dictionary<ManagementPromoItemSub, Dictionary<string, ManagementPromoItemPeriod>>());
                        foreach (XElement element in document.Element("root").Descendants("sub"))
                        {
                            Dictionary<string, ManagementPromoItemPeriod> dictionary = new Dictionary<string, ManagementPromoItemPeriod>();
                            ManagementPromoItemSub key = new ManagementPromoItemSub();
                            key.c(d(element.Attribute("id").Value));
                            key.b(d(element.Attribute("name").Value));
                            key.a(d(element.Attribute("type").Value));
                            item.c().Add(key, dictionary);
                            foreach (XElement element2 in element.Descendants("period"))
                            {
                                ManagementPromoItemPeriod period = new ManagementPromoItemPeriod();
                                period.a(d(element2.Attribute("cost").Value));
                                if (flag)
                                {
                                    period.c(d(element2.Attribute("discount").Value));
                                }
                                else
                                {
                                    period.c("0");
                                }
                                period.b(d(element2.Value));
                                dictionary.Add(d(element2.Attribute("id").Value), period);
                            }
                        }
                        item.a(new Dictionary<string, string>());
                        foreach (XElement element3 in document.Element("root").Descendants("pkod"))
                        {
                            item.d().Add(d(element3.Value), d(element3.Attribute("discount").Value));
                        }
                        return item;
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ManagementPromo", exception);
                    return null;
                }
            }
            return null;
        }

        protected static string d(string A_0)
        {
            return Encoding.UTF8.GetString(Convert.FromBase64String(A_0));
        }

        public static string[] d(string A_0, out string A_1)
        {
            A_1 = "";
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=wizard_cancel&order_id={0}", A_0) + a());
                    if (document != null)
                    {
                        string[] strArray = new string[2];
                        if (d(document.Element("root").Element("auth").Value).Length == 4)
                        {
                            if (document.Element("root").Element("error") != null)
                            {
                                A_1 = d(document.Element("root").Element("error").Value);
                                if (A_1 == "nosub")
                                {
                                    A_1 = e.c("There is no that Subscription. Update your data.");
                                    return strArray;
                                }
                                A_1 = e.c("You can not return this Subscription.");
                                return strArray;
                            }
                            strArray[0] = d(document.Element("root").Element("return_money").Value);
                            strArray[1] = d(document.Element("root").Element("balance_money").Value);
                            return strArray;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("CancelSubscriptionInfo", exception);
                    return null;
                }
            }
            return null;
        }

        public static List<NewsItem> e()
        {
            List<NewsItem> list = new List<NewsItem>();
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", "deistvo=notify" + a());
                    if ((document == null) || (d(document.Element("root").Element("auth").Value).Length != 4))
                    {
                        return list;
                    }
                    foreach (XElement element in document.Element("root").Descendants("sub"))
                    {
                        NewsItem item = new NewsItem();
                        item.a(a(d(element.Value)));
                        item.a(d(element.Attribute("usernamevpn").Value));
                        item.a(NewsState.New);
                        list.Add(item);
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("GetSubscriptionsExpDate", exception);
                    return list;
                }
            }
            return list;
        }

        public static string e(string A_0)
        {
            string str = a(DateTime.Now).ToString();
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=save_key&date={0}&link={1}", str, A_0) + a());
                    if (((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4)) && (document.Element("root").Element("secret_key") != null))
                    {
                        return d(document.Element("root").Element("secret_key").Value);
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("GetAccessToken", exception);
                    return "";
                }
            }
            return "";
        }

        public static List<NewsItem> f()
        {
            List<NewsItem> list = new List<NewsItem>();
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", "deistvo=notify_news" + WebRequestManager.a());
                    if ((document == null) || (d(document.Element("root").Element("auth").Value).Length != 4))
                    {
                        return list;
                    }
                    if (!System.IO.File.Exists(ConfigManager.q() + "/settings/news.xml"))
                    {
                        XmlDocument document2 = new XmlDocument();
                        document2.AppendChild(document2.CreateXmlDeclaration("1.0", "utf-8", null));
                        XmlElement newChild = document2.CreateElement("newsdata");
                        document2.AppendChild(newChild);
                        document2.Save(ConfigManager.q() + "/settings/news.xml");
                    }
                    XDocument other = XDocument.Load(ConfigManager.q() + "/settings/news.xml");
                    IEnumerable<XElement> source = other.Element("newsdata").Descendants("news");
                    DateTime time = DateTime.Parse(ConfigManager.b("newsdate"));
                    foreach (XElement element2 in document.Element("root").Descendants("news"))
                    {
                        DateTime time2 = WebRequestManager.a(d(element2.Attribute("date").Value));
                        if ((time2 - time) > TimeSpan.FromSeconds(1.0))
                        {
                            XElement content = new XElement("news");
                            content.Add(new XAttribute("date", time2.ToString()));
                            content.Add(new XAttribute("lacaldate", DateTime.Now.ToString()));
                            content.Add(new XCData(d(element2.Value)));
                            other.Element("newsdata").Add(content);
                            NewsItem item = new NewsItem();
                            item.a(DateTime.Now);
                            item.a(d(element2.Value));
                            item.a(NewsState.New);
                            list.Add(item);
                        }
                    }
                    if (source.Count<XElement>() > 0)
                    {
                        if (WebRequestManager.a == null)
                        {
                            WebRequestManager.a = new Func<XElement, long>(WebRequestManager.a);
                        }
                        ConfigManager.a("newsdate", DateTime.FromFileTime(source.Max<XElement>(WebRequestManager.a)).ToString());
                    }
                    XDocument document4 = new XDocument(other);
                    int num = (ConfigManager.b("notifydeletedays") == "Immediately") ? 0 : int.Parse(ConfigManager.b("notifydeletedays"));
                    using (IEnumerator<XElement> enumerator2 = document4.Descendants("news").GetEnumerator())
                    {
                        Func<XElement, bool> predicate = null;
                        XElement a;
                        while (enumerator2.MoveNext())
                        {
                            a = enumerator2.Current;
                            if ((DateTime.Now - DateTime.Parse(a.Attribute("lacaldate").Value)) > TimeSpan.FromDays((double) num))
                            {
                                if (predicate == null)
                                {
                                    <>c__DisplayClass5 class2;
                                    predicate = new Func<XElement, bool>(class2.b);
                                }
                                other.Descendants("news").Where<XElement>(predicate).Remove<XElement>();
                            }
                        }
                    }
                    other.Save(ConfigManager.q() + "/settings/news.xml");
                }
                catch (Exception exception)
                {
                    ConfigManager.a("GetNews", exception);
                    return list;
                }
            }
            return list;
        }

        public static bool f(string A_0)
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=settings_main_icq&icq_new={0}", A_0) + a());
                    if (((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4)) && ((document.Element("root").Element("result") != null) && (d(document.Element("root").Element("result").Value).Length == 4)))
                    {
                        return true;
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ChangeICQ", exception);
                    return false;
                }
            }
            return false;
        }

        public static void g()
        {
            string str = ConfigManager.b("p12");
            string str2 = ConfigManager.b("setauto");
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=wizardsetup&set_p12={0}&set_auto={1}&os_type=win", str, str2) + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        DirectoryInfo info = new DirectoryInfo(ConfigManager.q() + "/config/");
                        foreach (FileInfo info2 in info.GetFiles())
                        {
                            try
                            {
                                info2.Delete();
                            }
                            catch
                            {
                            }
                        }
                        foreach (XElement element in document.Element("root").Descendants("file"))
                        {
                            System.IO.File.WriteAllBytes(ConfigManager.q() + "/config/" + ((element.Attribute("icon") != null) ? (d(element.Attribute("icon").Value) + "_") : "") + d(element.Attribute("name").Value), Convert.FromBase64String(element.Value));
                            if (element.Attribute("dns") != null)
                            {
                                System.IO.File.AppendAllText(ConfigManager.q() + "/config/" + ((element.Attribute("icon") != null) ? (d(element.Attribute("icon").Value) + "_") : "") + d(element.Attribute("name").Value), Environment.NewLine + Environment.NewLine + "#DNS " + Encoding.ASCII.GetString(Convert.FromBase64String(element.Attribute("dns").Value)));
                            }
                        }
                        foreach (XElement element2 in document.Element("root").Descendants("icon"))
                        {
                            if (info.GetFiles(d(element2.Attribute("name").Value) + ".png").Length == 0)
                            {
                                System.IO.File.WriteAllBytes(ConfigManager.q() + "/config/" + d(element2.Attribute("name").Value) + ".png", Convert.FromBase64String(element2.Value));
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("GetConfigFiles", exception);
                }
            }
        }

        public static string g(string A_0)
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", string.Format("deistvo=settings_main_email&email_new={0}", A_0) + a());
                    if (((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4)) && ((document.Element("root").Element("result") != null) && (d(document.Element("root").Element("result").Value).Length == 4)))
                    {
                        return e.c("ChangeEmailOkMessage");
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("ChangeEmail", exception);
                    return e.c("ChangeEmailNotOkMessage");
                }
            }
            return e.c("ChangeEmailNotOkMessage");
        }

        public static string[] h()
        {
            if (AgentUser.a() != null)
            {
                try
                {
                    XDocument document = c("https://thesafety.us/billing/gui/guio", "deistvo=settings_main" + a());
                    if ((document != null) && (d(document.Element("root").Element("auth").Value).Length == 4))
                    {
                        return new string[] { ((document.Element("root").Element("icq") != null) ? d(document.Element("root").Element("icq").Value) : ""), ((document.Element("root").Element("email") != null) ? d(document.Element("root").Element("email").Value) : ""), ((document.Element("root").Element("license").Attribute("name") != null) ? d(document.Element("root").Element("license").Attribute("name").Value) : "") };
                    }
                }
                catch (Exception exception)
                {
                    ConfigManager.a("GetSettingsMain", exception);
                    return null;
                }
            }
            return null;
        }

        protected static string CommonQuery
        {
            get
            {
                return ("&glog80=" + AgentUser.a().d() + "&rpass3t=" + AgentUser.a().e() + "&lang=" + e.b() + "&ver=1.2");
            }
        }
    }
}

